// RemEditDialog.cpp : implementation file
//

#include "stdafx.h"

#include "RemEditDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRemEditDialog dialog


CRemEditDialog::CRemEditDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CRemEditDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRemEditDialog)
	m_text = _T("");
	m_time = COleDateTime::GetCurrentTime();
	//}}AFX_DATA_INIT

	m_pini=NULL;
}


void CRemEditDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRemEditDialog)
	DDX_Control(pDX, IDC_COMBO, m_combo);
	DDX_Text(pDX, IDC_EDIT, m_text);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER, m_time);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRemEditDialog, CDialog)
	//{{AFX_MSG_MAP(CRemEditDialog)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRemEditDialog message handlers

void CRemEditDialog::FillCombo()
{
	ASSERT(m_pini!=NULL);

	CString Key=m_pini->FindFirstKey();
	CString S,D;
	CString s=KEY_TYPE;
	s.MakeLower();	
	int N,n;
	DWORD NSel=0;

	while (Key!="")	
	{	if (Key.GetLength()>s.GetLength())
		{	S=Key;
			S.MakeLower();
			if (S.Mid(0,s.GetLength())==s)
			{	N=atoi(S.Mid(s.GetLength()));
				D=m_pini->GetValue(Key,"Descr");
				if (D!="")
				{	n=m_combo.AddString(D);
					m_combo.SetItemData(n,N);
					if (D==m_type) NSel=N;
				}
			}
		}
		Key=m_pini->FindNextKey();
	}


	for (n=0;n<m_combo.GetCount();n++) if (m_combo.GetItemData(n)==NSel) 
	{	m_combo.SetCurSel(n);
		return;
	}

	m_combo.SetCurSel(0);
}



BOOL CRemEditDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();

	FillCombo();


	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CRemEditDialog::OnOK() 
{
	m_combo.GetWindowText(m_type);
	
	CDialog::OnOK();
}
